package com.tmt.im.manager;

import com.tmt.data.jpa.repository.TmtBaseRepoImpl;
import com.tmt.im.manager.service.Initializer;
import com.tmt.springboot.chain._EnableDynamicInterfaces;
import com.tmt.springboot.common.annotation._EnableOpenApi;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/8/4 10:41
 * @Version 1.0
 **/
@Slf4j
@_EnableOpenApi
@_EnableDynamicInterfaces
@SpringBootApplication
@EnableTransactionManagement
@EnableWebMvc
@EnableAsync
@EntityScan({"com.tmt.im.jpa.entity"})
@EnableJpaRepositories(
        basePackages = {"com.tmt.im.jpa.repository"},
        repositoryBaseClass = TmtBaseRepoImpl.class)
public class IMManagerApplication implements ApplicationListener<ApplicationReadyEvent>, ApplicationContextAware {

    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(IMManagerApplication.class, args);
    }

    @Override
    public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        Initializer initializer = applicationContext.getBean(Initializer.class);
        initializer.initialize(applicationContext, IMManagerApplication.class);
        System.out.println("------IMManagerApplication启动完毕-------");
    }
}